package com.yun.platform;

import com.google.common.collect.Lists;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.*;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.service.ParameterType;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.List;

/**
 * @author laich
 * @date 2021-09-09
 * swagger配置文件+ jwt 认证
 * 打开方式： swagger-ui.html
 */
@Configuration
@ComponentScan("com.yun.platform")
@EnableOpenApi
public class Swagger2Config {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .apis(RequestHandlerSelectors.basePackage("com.yun.platform"))
                .paths(PathSelectors.regex("/.*"))
                .build()
                .globalRequestParameters(Lists.newArrayList(
                        new RequestParameterBuilder()
                                .name("Authorization")
                                .description("云平台API")
                                .in(ParameterType.HEADER)
                                .build()))
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("yun云平台-api文档")
                .version("v2.0")
                .build();
    }
}
